import {
  reqIntegratedInfo,
  reqNewcomerInfo,
  reqPopTrainingInfo,
  reqOriginal,
} from "@/api/index/original";
import { ElMessage } from "element-plus";
import { ref, onMounted } from "vue";

const useOriginal = () => {
  const originalList = ref<any>([]); //列表初始数据
  const pageSize = ref<number>(20);
  const pageNum = ref<number>(1);
  const initData = async () => {
    try {
      const result = await reqIntegratedInfo(pageSize.value, pageNum.value);
      originalList.value = result.content;
    } catch (error: any) {
      ElMessage.error(error.value);
    }
  };
  onMounted(() => {
    initData();
  });
  /**-----------------------   当前高亮  ---------------------------------- */
  const isActive = ref<number>(0);
  const changeList = async (num: number) => {
    isActive.value = num;
    try {
      switch (num) {
        case 0:
          initData();
          break;
        case 1:
          const result01 = await reqPopTrainingInfo(
            pageSize.value,
            pageNum.value
          );
          originalList.value = result01.content;
          break;

        case 2:
          const result02 = await reqNewcomerInfo(pageSize.value, pageNum.value);
          originalList.value = result02.content;
          break;
        default:
          initData();
          break;
      }
    } catch (error: any) {
      ElMessage.error(error.value);
    }
  };
  /**--------------------  获取可隐藏的动态条件  ------------------------ */
  const condition = ref<any>([]);
  const initCondition = async () => {
    try {
      const result = await reqOriginal();
      condition.value = result.content;
    } catch (error: any) {
      ElMessage.error(error.message);
    }
  };
  onMounted(() => {
    initCondition();
  });
  /**-------------------------  点击筛选按钮弹出下拉框  --------------------- */
  const isPop = ref<boolean>(false);
  const changePop = () => {
    console.log( isPop.value);
    
    isPop.value = !isPop.value;
  };
  /**----------------- 数据暴露   ------------------------------ */
  return { originalList, isActive, condition, isPop, changeList, changePop };
};
export default useOriginal;
